package utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataConn {   //shift+ctrl+o
	//1�������ݿ�ķ���
    public static Connection getConn() {
    	Connection  conn = null;
			try {
				Class.forName("com.mysql.cj.jdbc.Driver");//��̬����������
				conn = DriverManager.getConnection(
		    			"jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&serverTimezone=UTC&useSSL=false",
		    			"root",
		    			"123456");  //��ȡ���Ӷ���
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}		
    	return conn;
    }
    //2 �ر����ݿ�����
    public static void closeConn(Connection conn) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    }
	public static void main(String[] args) {
		 Connection conn=DataConn.getConn();
		if(conn!=null) {
			System.out.println("success");
		}else {
			System.out.println("fail");
		}
	}

}
